import datetime

import arrow as arrow
from django.shortcuts import render

from rest_framework import filters
import json
from django.core import serializers

from rest_framework.decorators import action
from rest_framework.response import Response

# from import_module.models import MaintenancePlanningItem, EntityBomNodeSelection
from apps.equipment_maintenance_plan.models import MaintenanceSchedule, MaintenanceScheduleContent, polish_line
from apps.equipment_maintenance_plan.serializer import MaintenanceScheduleSerializer, MaintenanceScheduleContentSerializer, PolishLineSerializer
from apps.equipment_maintenance_plan.filters import MaintenanceScheduleFilter, MaintenanceScheduleContentFilter


from rest_framework import viewsets
from django_filters.rest_framework import DjangoFilterBackend


# Create your views here.
class MaintenanceScheduleContentViewSet(viewsets.ModelViewSet):
    queryset = MaintenanceScheduleContent.objects.all()
    serializer_class = MaintenanceScheduleContentSerializer
    filter_backends = [DjangoFilterBackend, filters.OrderingFilter]
    filter_class = MaintenanceScheduleContentFilter
    ordering_fields = ['datetime']


class MaintenanceScheduleViewSet(viewsets.ModelViewSet):
    queryset = MaintenanceSchedule.objects.all()
    serializer_class = MaintenanceScheduleSerializer
    filter_backends = [DjangoFilterBackend]
    filter_class = MaintenanceScheduleFilter

class PolisheLineViewSet(viewsets.ModelViewSet):
    queryset = polish_line.objects.all()
    serializer_class = PolishLineSerializer

